package com.shaoshaohuo.app.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.entity.PayAccount;
import com.shaoshaohuo.app.entity.SupportWithdrawWay;

import java.util.List;

public class PayAccountAdapter<T> extends MyBaseAdapter<PayAccount> {

	public PayAccountAdapter(Context ctx, List<PayAccount> list, boolean flag) {
		super(ctx, list, flag);
	}

	@Override
	public View getView(int pos, View convertView, ViewGroup group) {
		if (convertView == null) {
			convertView = View.inflate(context,R.layout.item_pay_account,null);
		}
		PayAccount payAccount = list.get(pos);
		ViewHolder holder = ViewHolder.getHolder(convertView);
		if("1".equals(payAccount.isDefault)){
			holder.iv_default.setVisibility(View.VISIBLE);
		}else if ("0".equals(payAccount.isDefault)) {
			holder.iv_default.setVisibility(View.INVISIBLE);
		}
		holder.tv_bank_name.setText(payAccount.title);
		holder.tv_card_num.setText("**** **** **** "+payAccount.account.substring(payAccount.account.length()-4));
		holder.tv_name.setText(payAccount.realname);
		holder.tv_phone.setText(payAccount.mobile);
		return convertView;
	}



	static class ViewHolder{
		public  ImageView iv_default;
		public	TextView tv_bank_name;
		public	TextView tv_card_num;
		public	TextView tv_name;
		public  TextView tv_phone;

		public ViewHolder(View convertView) {
			iv_default = (ImageView) convertView.findViewById(R.id.iv_default);
			tv_bank_name = (TextView) convertView.findViewById(R.id.tv_bank_name);
			tv_card_num = (TextView) convertView.findViewById(R.id.tv_card_num);
			tv_name = (TextView) convertView.findViewById(R.id.tv_name);
			tv_phone = (TextView) convertView.findViewById(R.id.tv_phone);
		}

		public static ViewHolder getHolder(View convertView){
			return (ViewHolder) (convertView.getTag() != null ? convertView.getTag() : new ViewHolder(convertView));
		}
	}


}
